home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / perl5 / Gnome2 / VFS.pm < prev    next >
Text File  |  2008-02-24  |  5KB  |  201 lines

  1. # $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gnome2-VFS/VFS.pm,v 1.39 2008/02/24 15:32:04 kaffeetisch Exp $
  2.  
  3. package Gnome2::VFS;
  4.  
  5. use 5.008;
  6. use strict;
  7. use warnings;
  8.  
  9. use Glib;
  10.  
  11. require Exporter;
  12. require DynaLoader;
  13.  
  14. our @ISA = qw(Exporter DynaLoader);
  15.  
  16. our @EXPORT_OK = qw(
  17.   GNOME_VFS_PRIORITY_MIN
  18.   GNOME_VFS_PRIORITY_MAX
  19.   GNOME_VFS_PRIORITY_DEFAULT
  20.   GNOME_VFS_SIZE_FORMAT_STR
  21.   GNOME_VFS_OFFSET_FORMAT_STR
  22.   GNOME_VFS_MIME_TYPE_UNKNOWN
  23.   GNOME_VFS_URI_MAGIC_STR
  24.   GNOME_VFS_URI_PATH_STR
  25. );
  26.  
  27. # --------------------------------------------------------------------------- #
  28.  
  29. our $VERSION = '1.081';
  30.  
  31. sub import {
  32.   my ($self) = @_;
  33.   my @symbols = ();
  34.  
  35.   foreach (@_) {
  36.     if (/^-?init$/) {
  37.       $self -> init();
  38.     } else {
  39.       push @symbols, $_;
  40.     }
  41.   }
  42.  
  43.   Gnome2::VFS -> export_to_level(1, @symbols);
  44. }
  45.  
  46. sub dl_load_flags { $^O eq 'darwin' ? 0x00 : 0x01 }
  47.  
  48. Gnome2::VFS -> bootstrap($VERSION);
  49.  
  50. # --------------------------------------------------------------------------- #
  51.  
  52. use constant GNOME_VFS_PRIORITY_MIN => -10;
  53. use constant GNOME_VFS_PRIORITY_MAX => 10;
  54. use constant GNOME_VFS_PRIORITY_DEFAULT => 0;
  55.  
  56. use constant GNOME_VFS_SIZE_FORMAT_STR => "Lu";
  57. use constant GNOME_VFS_OFFSET_FORMAT_STR => "Ld";
  58.  
  59. use constant GNOME_VFS_MIME_TYPE_UNKNOWN => "application/octet-stream";
  60.  
  61. use constant GNOME_VFS_URI_MAGIC_STR => "#";
  62. use constant GNOME_VFS_URI_PATH_STR => "/";
  63.  
  64. 1;
  65.  
  66. # --------------------------------------------------------------------------- #
  67.  
  68. __END__
  69.  
  70. =head1 NAME
  71.  
  72. Gnome2::VFS - Perl interface to the 2.x series of the GNOME VFS library
  73.  
  74. =head1 SYNOPSIS
  75.  
  76.   use Gnome2::VFS;
  77.  
  78.   sub die_already {
  79.     my ($action) = @_;
  80.     die("An error occured while $action.\n");
  81.   }
  82.  
  83.   die_already("initializing GNOME VFS") unless (Gnome2::VFS -> init());
  84.  
  85.   my $source = "http://www.perldoc.com/about.html";
  86.   my ($result, $handle, $info);
  87.  
  88.   # Open a connection to Perldoc.
  89.   ($result, $handle) = Gnome2::VFS -> open($source, "read");
  90.   die_already("opening connection to '$source'")
  91.     unless ($result eq "ok");
  92.  
  93.   # Get the file information.
  94.   ($result, $info) = $handle -> get_file_info("default");
  95.   die_already("retrieving information about '$source'")
  96.     unless ($result eq "ok");
  97.  
  98.   # Read the content.
  99.   my $bytes = $info -> { size };
  100.  
  101.   my $bytes_read = 0;
  102.   my $buffer = "";
  103.  
  104.   do {
  105.     my ($tmp_buffer, $tmp_bytes_read);
  106.  
  107.     ($result, $tmp_bytes_read, $tmp_buffer) =
  108.       $handle -> read($bytes - $bytes_read);
  109.  
  110.     $buffer .= $tmp_buffer;
  111.     $bytes_read += $tmp_bytes_read;
  112.   } while ($result eq "ok" and $bytes_read < $bytes);
  113.  
  114.   die_already("reading $bytes bytes from '$source'")
  115.     unless ($result eq "ok" && $bytes_read == $bytes);
  116.  
  117.   # Close the connection.
  118.   $result = $handle -> close();
  119.   die_already("closing connection to '$source'")
  120.     unless ($result eq "ok");
  121.  
  122.   # Create and open the target.
  123.   my $target = "/tmp/" . $info -> { name };
  124.   my $uri = Gnome2::VFS::URI -> new($target);
  125.  
  126.   ($result, $handle) = $uri -> create("write", 1, 0644);
  127.   die_already("creating '$target'") unless ($result eq "ok");
  128.  
  129.   # Write to it.
  130.   my $bytes_written;
  131.  
  132.   ($result, $bytes_written) = $handle -> write($buffer, $bytes);
  133.   die_already("writing $bytes bytes to '$target'")
  134.     unless ($result eq "ok" && $bytes_written == $bytes);
  135.  
  136.   # Close the target.
  137.   $result = $handle -> close();
  138.   die_already("closing '$target'") unless ($result eq "ok");
  139.  
  140.   Gnome2::VFS -> shutdown();
  141.  
  142. =head1 ABSTRACT
  143.  
  144. This module allows you to interface with the GNOME Virtual File System library.
  145. It provides the means to transparently access files on all kinds of
  146. filesystems.
  147.  
  148. =head1 DESCRIPTION
  149.  
  150. Since this module tries to stick very closely to the C API, the documentation
  151. found at
  152.  
  153.   L<http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/>
  154.  
  155. is the canonical reference.
  156.  
  157. In addition to that, there's also the automatically generated API
  158. documentation: L<Gnome2::VFS::index>.
  159.  
  160. The mapping described in L<Gtk2::api> also applies to this module.
  161.  
  162. To discuss this module, ask questions and flame/praise the authors, join
  163. gtk-perl-list@gnome.org at lists.gnome.org.
  164.  
  165. =head1 KNOWN BUGS
  166.  
  167. There are some memory leaks especially with respect to callbacks.  This mainly
  168. affects GnomeVFSAsync as well as some parts of GnomeVFSXfer and GnomeVFSOps.
  169. GnomeVFSMime leaks some list data.
  170.  
  171. GnomeVFSAsync is also known to crash under certain conditions when there are
  172. many concurrent transfers.
  173.  
  174. =head1 SEE ALSO
  175.  
  176. L<Gnome2::VFS::index>, L<Glib>, L<Gtk2>, L<Gtk2::api>.
  177.  
  178. =head1 AUTHOR
  179.  
  180. Torsten Schoenfeld E<lt>kaffeetisch@web.deE<gt>.
  181.  
  182. =head1 COPYRIGHT AND LICENSE
  183.  
  184. Copyright (C) 2003-2007 by the gtk2-perl team (see the file AUTHORS)
  185.  
  186. This library is free software; you can redistribute it and/or modify it under
  187. the terms of the GNU Lesser General Public License as published by the Free
  188. Software Foundation; either version 2.1 of the License, or (at your option) any
  189. later version.
  190.  
  191. This library is distributed in the hope that it will be useful, but WITHOUT ANY
  192. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  193. PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
  194. details.
  195.  
  196. You should have received a copy of the GNU Lesser General Public License along
  197. with this library; if not, write to the Free Software Foundation, Inc.,
  198. 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  199.  
  200. =cut
  201.